package metier.sess;

import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import metier.entities.Transport;


@Stateless(name="Transport")
public class TransportEJBImpl implements ITransportLocal,ITransportRemote{
	@PersistenceContext(unitName="PU_Cargaison")
	private EntityManager em;

	@Override
	public void addTransport(Transport t) {
		em.merge(t);
	}

	@Override
	public List<Transport> getAllTransport() {
		Query req=em.createQuery("select t from Transport t");
		return req.getResultList();
	}
	
	@Override
	public List<Transport> getAllActiveTransport() {
		Query req=em.createQuery("select t from Transport t where t.Statut=true");
		return req.getResultList();
	}

	@Override
	public Transport getTransport(Integer Id) {
		Transport tr=em.find(Transport.class, Id);
		return tr;
	}

	@Override
	public void updateTransport(Transport t) {
		em.merge(t);
		
	}

	@Override
	public void deleteTransport(Integer Id) {
		Transport tr=getTransport(Id);
		em.remove(tr);
		
	}
	

}
